package com.whnk.web.controller.pm;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.BusitripInfo;
import com.whnk.pm.service.IBusitripInfoService;

/**
 * 出差 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-08-16
 */
@Controller
@RequestMapping("/pm/busitripInfo")
public class BusitripInfoController extends BaseController
{
    private String prefix = "pm/busitripInfo";
	
	@Autowired
	private IBusitripInfoService busitripInfoService;
	
	@RequiresPermissions("pm:busitripInfo:view")
	@GetMapping()
	public String busitripInfo()
	{
	    return prefix + "/busitripInfo";
	}
	
	/**
	 * 查询出差列表
	 */
	@RequiresPermissions("pm:busitripInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(BusitripInfo busitripInfo)
	{
		startPage();
        List<BusitripInfo> list = busitripInfoService.selectBusitripInfoList(busitripInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增出差
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存出差
	 */
	@RequiresPermissions("pm:busitripInfo:add")
	@Log(title = "出差", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(BusitripInfo busitripInfo)
	{		
		return toAjax(busitripInfoService.insertBusitripInfo(busitripInfo));
	}

	/**
	 * 修改出差
	 */
	@GetMapping("/edit/{busiId}")
	public String edit(@PathVariable("busiId") Integer busiId, ModelMap mmap)
	{
		BusitripInfo busitripInfo = busitripInfoService.selectBusitripInfoById(busiId);
		mmap.put("busitripInfo", busitripInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存出差
	 */
	@RequiresPermissions("pm:busitripInfo:edit")
	@Log(title = "出差", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(BusitripInfo busitripInfo)
	{		
		return toAjax(busitripInfoService.updateBusitripInfo(busitripInfo));
	}
	
	/**
	 * 删除出差
	 */
	@RequiresPermissions("pm:busitripInfo:remove")
	@Log(title = "出差", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(busitripInfoService.deleteBusitripInfoByIds(ids));
	}
	
	/**
	 * 查看详细信息
	 * 
	 * @param busiId
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("pm:busitripInfo:detail")
    @GetMapping("/detail/{busiId}")
    public String detail(@PathVariable("busiId") Integer busiId, ModelMap mmap)
	{
		BusitripInfo busitripInfo = busitripInfoService.selectBusitripInfoById(busiId);
		mmap.put("busitripInfo", busitripInfo);
        return prefix + "/detail";
    }
}
